import Vue from 'vue'
import Vuex from 'vuex'
import login from './modules/login'
import user from './modules/user'
Vue.use(Vuex)

export default new Vuex.Store({
	// 1. 仓库中的状态
	state: {
		count: 666,
	},
	// 2. 仓库中计算属性
	getters: {
		totalPrice: function (state) {
			return state.count * 10
		},
	},
	// 3. 同步的修改
	mutations: {
		// increase:function(){}
		INCREASE(state, payload) {
			console.log('执行increase:', state, payload)
			state.count += payload.num
		},
	},
	// 4. 异步的修改
	actions: {
		// 名字 increaseSync
		increaseSync: function (store, payload) {
			console.log('执行 increaseSync，数据：', payload)
			// 异步操作
			setTimeout(function () {
				store.commit('INCREASE', payload)
			}, 200)
		},
	},
	// 5. 通过module对上面四个模块进行划分
	modules: {
		login,
		user,
	},
})
